package com.advert.presentation.bean;

import com.advert.config.Config;
import org.jboss.seam.annotations.Create;
import org.jboss.seam.annotations.In;

import java.io.Serializable;

public abstract class PageAwareBeanBase implements Serializable {
    @In("config")
    private Config config;

    private Integer advertsToDisplay;
    private String page;
    

    public String getPage() {
        return page;
    }

    public void setPage(String page) {
        this.page = page;
    }

    public Integer getAdvertsToDisplay() {
        return advertsToDisplay;
    }

    public int getPageNumber() {
        int retVal = 1;
        if (getPage() != null) {
            if (getPage().equals("last")) {
                retVal = getPageCount();
            } else {
                try {
                    retVal = Integer.parseInt(getPage());
                } catch (NumberFormatException e) {}
            }
        }
        return retVal;
    }

    public abstract int getPageCount();


    @Create
    public void init() {
        advertsToDisplay = config.getAdvertsToDisplay();
    }
}
